
#coding:utf-8    
#使用自己的域名后，加上共享IP，发了2个QQ邮件，是可以送到的
#发送 11万封邮件，得到 1万的转化率 5%
#每天发2000封邮件, 单数

import requests                                                          
import hashlib
import time
import csv


url="http://api.sendcloud.net/apiv2/mail/send"                       
filepath = '//Users//elsa//Desktop//proj//python//jd_maotai//learning_notebook-master//qqemail//splitdata//split_1.csv'

csv_reader = csv.reader(open(filepath, encoding='utf-8'))

for row in csv_reader:
    #date|  name  |qq  
    rowarray =  len(row)  
    rowdate = row[1]
    
    if rowarray>3 and rowdate!='datetime' :
        
        rowname = row[2]
        rowqq = row[3]+'@qq.com'
        
        print(rowdate,rowname,rowqq)
          
        qq_subject = rowname+" 百-万-比_特-币大赠送、亚洲最大的场-外-交-易平台"
    
        #hash_subject = hashlib.md5()   
        #hash_subject.update(qq_subject.encode('utf-8'))   
        #qq_subject = qq_subject + hash_subject.hexdigest() 
  
        qq_html = " <p>  \
<span style='background-color:;'></span> \
</p> \
<h1 style='text-align:center;font-size:41px;font-family:Raleway, &quot;color:white;background-color:#2C3E50;'> \
	<span style='color:aqua;'>Coin</span>2<span style='color:coral;'>World</span> \
</h1> \
<span style='font-family:Helvetica, &quot;'></span> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	&nbsp; <span style='font-size:14px;'>您好： " + rowname
    
        qq_html = qq_html + "</span> </p> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	<span style='font-size:14px;'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style='font-size:14px;'>Coin2World总部位于国际金-融中心新加坡，<span style='color:#009900;font-size:16px;'><strong>正规交易牌照</strong></span>，由专业的国际化团队研发与运营，专注于为全球用户提供安全、便捷的比-特-币场-外-交-易服务。</span>  \
</p> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	<span style='font-size:14px;'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 活动期间，</span><em><strong><span style='font-size:16px;color:#009900;'>价值百-万-比_特-币大放送</span></strong></em><span style='font-size:14px;'><em><span style='font-size:14px;'>，</span></em><span style='font-size:14px;'>注-册就送比-特-币，先到先得。</span></span> \
</p> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	<span style='font-size:14px;'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 注-册地址:&nbsp; &nbsp; &nbsp; <span style='color:#337FE5;'>https://www.coin2world.com/register.html</span></span>  \
</p> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	<span style='font-size:14px;'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style='font-size:16px;'>&nbsp;</span></span><strong><span style='font-size:16px;color:#009900;'>邀-请好友注-册、交-易-费全返、多邀-请多返-俑</span></strong>  \
</p> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	<span style='font-size:14px;'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 现在就邀-请：<span style='color:#337FE5;'>https://www.coin2world.com/invite.html</span></span>  \
</p> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	<span style='font-size:14px;'>&nbsp;</span>  \
</p> \
<p style='font-family:Helvetica, &quot;font-size:14px;'> \
	<span style='font-size:14px;'>&nbsp;Coin2World Team</span>  </p> <p> <br /> </p>"
    
    
        hash_html  = hashlib.sha256()
        hash_html.update(qq_html.encode('utf-8'))
        qq_html    = qq_html + hash_html.hexdigest()
   
        # 您需要登录SendCloud创建API_USER，使用API_USER和API_KEY才可以进行邮件的发送。
        params = {"apiUser": "tomtao_8222_Qzo83E", \
                  "apiKey" : "Q5pqqRDfgjF739Th",\
                  "from" : "service@8222.studio", \
                  "fromName" : "Coin2World", \
                  "to" : rowqq, \
                  "subject" : qq_subject, \
                  "html": qq_html, \
              }
        print (params)
        r = requests.post(url, files={}, data=params)
        print ('send email return '+r.text)
        time.sleep(1)
        


